﻿using log4net.Core;
using System;

namespace log4net.extension.nsq
{
    public class ReplicateNSQAppender : NSQAppender
    {
        protected override void Append(LoggingEvent loggingEvent)
        {
            foreach (var kv in base.m_producerContainer)
            {
                var producer = kv.Value;
                try
                {
                    var message = GetLogEntity(loggingEvent);
                    producer.Publish(this.TopicName, Serialize(message));
                    break;
                }
                catch (Exception ex)
                {
                    HealthCheck(kv);
                    ErrorHandler.Error("Exception while writing to nsq", ex);
                }
            }
        }
    }
}
